import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);

/* 路由不需要异步加载区域 */
import Home from "../views/project-entrance/Home.vue";
import NotFound from "src/components/layout/404.vue";

/* 路由异步加载区域 */
/* ============账号管理模块=========== */
const account = () => import("src/views/account/account");
const loginComponent = () => import("src/views/account/login");

// 路由配置项
const routerConfig = {
  routes: [
    // 404
    {
      path: "*",
      name: "404",
      component: NotFound,
      meta: {
        requireAuth: false,
        title: "404",
      },
    },
    // 路由进入重定向
    {
      path: "/",
      redirect: "/account",
    },
    // 账号模块
    {
      path: "/account",
      name: "account",
      component: account,
      meta: {
        requireAuth: false,
      },
      redirect: "/account/login",
      children: [
        {
          path: "/account/login",
          name: "login",
          component: loginComponent,
          meta: {
            requireAuth: false,
            title: "登录",
          },
        },
      ],
    },
    // 主路由模块
    {
      path: "/home",
      name: "home",
      component: Home,
      meta: {
        requireAuth: true,
      },
      children: [],
    },
  ],
};

// 测试模块（生产模式下将不会引入）
// 在开发模式下才会引入的组件内容（测试组件一般放置在views/test文件夹中）
// 用于测试某些插件或自定义组件是否可以使用或者符合需求
if (process.env.NODE_ENV === "development") {
  routerConfig.routes = routerConfig.routes.concat([
    {
      // test
      path: "/test",
      name: "test",
      component: () => import("src/components/layout/404.vue"),
    },
  ]);
}

export default new Router(routerConfig);
